package coroutines.coroutinescope.exception

import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class GlobalScopeExceptionTest {
}

fun main() {
    GlobalScope.launch {
        /**
         * 顶级作用域自己直接跑出异常，还是会向上层传递，但是如果是顶级作用域的子协程跑出异常，这个异常传递到了顶级作用域，就不会继续传递
         * */
        GlobalScope.launch {
            delay(200)

            launch {
                delay(50)

                throw Throwable("2233娘")
            }
        }

        launch {
            delay(100)
            println("GlobalScope.launch launch() 0 ")
        }

        launch {
            delay(300)
            println("GlobalScope.launch launch() 1 ")
        }
    }

    try {
        Thread.sleep(100)

        println("main() 100ms")
    } catch (t: Throwable) {
        println("")
    }

    try {
        Thread.sleep(100)
        println("main() 200ms")
    } catch (t: Throwable) {
        println("")
    }

    try {
        Thread.sleep(200)
        println("main() 400ms")
    } catch (t: Throwable) {
        println("")
    }
}